﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    [CustomPropertyDrawer(typeof(MultilineAttribute))]
    internal sealed class MultilineDrawer : PropertyDrawer
    {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return (16f * (((MultilineAttribute) base.attribute).lines + 1));
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType == SerializedPropertyType.String)
            {
                label = EditorGUI.BeginProperty(position, label, property);
                GUI.Label(EditorGUI.IndentedRect(new Rect(position.x, position.y, position.width, 16f)), label, EditorStyles.label);
                position.yMin += 16f;
                EditorGUI.BeginChangeCheck();
                string str = EditorGUI.TextArea(position, property.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.stringValue = str;
                }
                EditorGUI.EndProperty();
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Multiline with string.");
            }
        }
    }
}

